package com.huike.pmps.controller;

import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.CustomerSuccess;
import com.huike.pmps.model.entity.Region;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.CustomerSuccessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author：张春旺(010101)
 * date: 2021-06-29
 * WeChat:18311488838
 * QQ:347329812
 */
@Api(tags = "客户成功管理")
@RestController
@RequestMapping("/api/customerSuccess")
public class CustomerSuccessController {

    @Autowired
    CustomerSuccessService customerSuccessService;

    @ApiOperation(value = "获取所有客户成功数据", httpMethod = "GET")
    @GetMapping("/all")
    public Result selectAll() {
        return customerSuccessService.selectAllCustomerSuccess();
    }

    @ApiOperation(value = "新增成功客户", httpMethod = "POST")
    @PostMapping
    public Result insertOne(CustomerSuccess customerSuccess) {
        return customerSuccessService.insertOne(customerSuccess);
    }

    @ApiOperation(value = "按搜索条件分页查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teamName", value = "客户成功团队名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "charge", value = "客户成功团队负责人", paramType = "query", dataType = "String")
    })
    @GetMapping
    public Result selectByCondition(PageInfo pageInfo, String teamName, String charge) {
        return customerSuccessService.selectByCondition(pageInfo, teamName, null, charge);
    }

    @ApiOperation(value = "根据id删除客户成功团队", httpMethod = "DELETE")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return customerSuccessService.deleteById(id);
    }

    @ApiOperation(value = "根据id修改客户成功团队", httpMethod = "PUT")
    @PutMapping
    public Result updateById(CustomerSuccess customerSuccess) {
        return customerSuccessService.updateById(customerSuccess);
    }

    @ApiOperation(value = "根据客户成功团队主键id,获取该客户成功团队下的子团队", httpMethod = "GET")
    @GetMapping("/{id}/subteams")
    public Result selectByParentId(@PathVariable("id") Integer parentId) {
        return customerSuccessService.selectByParentId(parentId);
    }

    @ApiOperation(value = "根据客户成功团队主键id,获取该客户成功团队下的子团队", httpMethod = "GET")
    @GetMapping("/tree")
    public Result selectByTree() {
        return customerSuccessService.selectByTree();
    }
}
